﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SachOnlineLibrary.DAL;
using SachOnlineLibrary.Public;
using System.Data;
/// <summary>
/// Summary description for DangKiBLL
/// </summary>
public class DangKiBLL
{
    TaiKhoanDAL taikhoanDAL = new TaiKhoanDAL();
	public DangKiBLL()
	{
	}
    public bool Taotk(TaiKhoan tk)
    {
        return taikhoanDAL.TaoTaiKhoan(tk);
    }
    //public bool SuaTK(TaiKhoan tk)
    //{
    //    return taikhoanDAL.SuaTaiKhoan(tk);
    //}
    public bool CheckTaiKhoan(string username)
    {
        if (taikhoanDAL.LayTaiKhoanTheoTen(username).Rows.Count > 0)
        {
            return true;
        }
        return false;
    }
    public bool CheckEmail(string email)
    {
        if (taikhoanDAL.LayTaiKhoanTheoEmail(email).Rows.Count > 0)
        {
            return true;
        }
        return false;
    }
    public string LayTaiKhoanTheoMail(string email)
    {
        return taikhoanDAL.LayTaiKhoanTheoEmail(email).Rows[0]["Ten"].ToString();
    }
    public List<TaiKhoan> LietKeTatCaTK()
    {
        List<TaiKhoan> listtaikhoan = new List<TaiKhoan>();
        DataTable dt = new DataTable();
        dt = taikhoanDAL.LayDSTaiKhoan();      
        foreach (DataRow dr in dt.Rows)
        {
            TaiKhoan item = new TaiKhoan();
            item.ChuyenDoi(dr);
            listtaikhoan.Add(item);          
        }
        return listtaikhoan;
    }
    public bool KichHoatTK(int ma, bool trangthai)
    {
        return taikhoanDAL.KichHoatTaiKhoan(ma, trangthai);
    }
}